package zeroj.web.format.impl;

import zeroj.helper.StringUtil;
import zeroj.web.format.IFormater;

/**
 * 
 * @author LYL(lylsir at gmail dot com)
 *
 */
public class StringFormater implements IFormater {

	private static StringFormater defaultInstance = new StringFormater(false, false, "");
	private boolean trim;
	private boolean lower;
	private String defaultValue;
	
	public static StringFormater getDefaultInstance() {
		
		return defaultInstance;
	}
	public StringFormater(boolean trim, boolean lower, String defaultValue) {
		
		this.trim = trim;
		this.lower = lower;
		this.defaultValue = defaultValue;
	}
	public Object format(String value) {
		
		if(StringUtil.isEmpty(value))
			return defaultValue;
		if(trim)
			value = value.trim();
		if(lower)
			value = value.toLowerCase();
		return value;
	}

}
